use crate::entities::{dish::Model as DishModel, dish_flavor::Model as DishFlavor};

use rust_decimal::Decimal;
use sea_orm::{prelude::DateTime, FromQueryResult};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
pub struct DishCountVO {
    total: u64,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct DishVO {
    pub id: Option<i64>,               // 菜品 ID
    pub name: Option<String>,          // 菜品名称
    pub category_id: Option<i64>,      // 分类 ID
    pub price: Option<Decimal>,        // 菜品价格 
    pub image: Option<String>,         // 图片路径
    pub description: Option<String>,   // 菜品描述
    pub status: Option<i32>,           // 状态 0:停售, 1:起售
    pub update_time: Option<DateTime>, // 更新时间
    pub category_name: Option<String>, // 分类名称
    pub flavors: Vec<DishFlavor>,      // 菜品关联的口味
}

impl From<DishModel> for DishVO {
    fn from(dish: DishModel) -> Self {
        Self {
            id: Some(dish.id),
            name: Some(dish.name),
            category_id: Some(dish.category_id),
            price: dish.price,
            image: dish.image,
            description: dish.description,
            status: dish.status,
            update_time: dish.update_time,
            category_name: Some(String::new()),
            flavors: Vec::new(),
        }
    }
}

#[derive(Debug, Deserialize, Serialize, FromQueryResult)]
pub struct DishItemVO {
    pub name: Option<String>,        // 菜品名称
    pub copies: Option<i32>,         // 份数
    pub image: Option<String>,       // 菜品图片
    pub description: Option<String>, // 菜品描述
}

#[derive(Debug, Deserialize, Serialize)]
pub struct DishOverViewVO {
    pub sold: Option<i32>,         // 已启售数量
    pub discontinued: Option<i32>, // 已停售数量
}
